<template>
	<view class="bg-white margin-top order-sel" @click="onOrder" :class="theme">
		<view class="flex align-center">
			<view class="yq-order">
				<text class="cuIcon-titles"></text>
				<text v-if="theme == 'fs'">已接订单</text>
				<text v-else>已发订单</text>
			</view>
			<view class="order-status flex-sub"
				:style="{'background-image': 'url(' + `${$hd.baseUrl}/images/${theme}/bg-rob.png` + ')'}">
				<text>状态：{{statusLabel}}</text>
				<!-- <text v-else>{{orderData.flyerName||'飞手'}}已接单</text> -->
			</view>
		</view>
		<view class="padding">
			<view class="flex align-center justify-between text-lg margin-tb-sm padding-sm radius-lg bg-spc">
				<view class="flex-sub">
					<view class="w-90 uv-line-1 text-black text-bold" :title="orderData.orderName">
						{{ orderData.orderName }}
					</view>
				</view>

				<view class="color-red">
					<text class="text-sm">￥</text>
					<text class="text-bold text-xl">{{orderData.actualMoney || orderData.money}}</text>
				</view>
			</view>
			<view class="">
				<view class='cu-tag bg-spc'>{{ orderData.cropName }}</view>
				<view class='cu-tag bg-spc' v-if="orderData.homeworkType == 1">面积{{ orderData.area }}亩</view>
				<view class='cu-tag bg-spc' v-else>重量{{ orderData.area }}吨</view>
				<view class='cu-tag bg-spc' v-if="orderData.cropAcreUsage">{{ orderData.cropAcreUsage }}L/亩</view>
			</view>
			<view class="text-gray margin-top-sm flex align-center">
				<view class="flex-sub text-cut">
					地址：{{orderData.address}}
				</view>
				<text class="color-blue margin-left">{{ orderData.distance || '-' }}</text>
			</view>
			<view class="flex align-center justify-between margin-top-xs">
				<view class="text-gray">
					<!-- <view>
						开始时间：{{orderData.homeworkStartTime}}
					</view> -->
					<view class="margin-top-xs">
						推荐作业时间：{{orderData.dockingPeopleTime|dateOnly}}
					</view>
				</view>
				<view class="color-red text-lg" style="width: 80rpx;">
					详情
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		selectDictLabel
	} from '@/utils/huida.js'
	import {
		mapGetters
	} from 'vuex'
	export default {
		// dicts: ["assign_orders_status", "crop_type"],
		props: {
			orderData: {
				type: Object,
				default: () => ({})
			},
			orderStatus: {
				type: Array,
				default: () => ([])
			}
		},
		filters: {
			dateOnly(value) {
				return value ? value.split(' ')[0] : '-';
			}
		},
		// 农户端
		computed: {
			...mapGetters(['theme']),
			statusLabel() {
				const {status,isStatus,commentStar,exceptionType,frozenReason} = this.orderData
				// console.log('status',status);
				// console.log('isStatus',isStatus);

				if (frozenReason && frozenReason.trim() !== '') {
					return selectDictLabel(this.orderStatus, '18');
				}

				let s = String(status);
				const is1 = String(isStatus) === '1';
				const is2 = String(isStatus) === '2';
				const is3 = String(isStatus) === '3';

				if (exceptionType == 2 && s == 13) {
					return selectDictLabel(this.orderStatus, s, 'reserved1');
				}
				if(exceptionType == 2 && s == 14) {
					return selectDictLabel(this.orderStatus, s, 'reserved1');
				}
				if(s === 17){
					return selectDictLabel(this.dict.type.assign_orders_status, '1');
				}
				// 农户订单状态
				if (this.theme === 'farmer') {
					console.log('isStatus', isStatus);
					console.log('111111', s);
					if (s === '6' && is2) {
						s = '8';
					}
					if (s === '6' && is3) {
						s = '8';
					}
					if (s === '7' && is1) {
						s = '8';
					}
					if (s === '8' && is2) {
						s = '8';
					}
					if (s === '9' && is1 && commentStar == null) {
						s = '8';
					}
					if (commentStar != null) {
						s = '9';
					}
					if(s === '17'){
						s = '1'
					}
				}

				if (this.theme === 'farmer' && ['1', '2', '6', '7', '8'].includes(s)) {
					return selectDictLabel(this.orderStatus, s, 'reserved1');
				}
				// 如果status=4 && isStatus=2，使用10的字典值
				if (s === '4' && is2) {
					return selectDictLabel(this.orderStatus, '10');
				}
				// 走原逻辑
				return selectDictLabel(this.orderStatus, s);
			}
		},
		methods: {
			selectDictLabel,
			onOrder() {
				uni.$uv.route({
					url: '/pages/taskDetail/index',
					params: {
						id: this.orderData.id,
						orderLogId: this.orderData.orderLogId
					}
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.order-sel {
		border-radius: 32rpx;
	}

	.yq-order {
		text-align: center;
		font-size: 34rpx;
		font-weight: 600;
		width: 30%;
	}

	.order-status {
		height: 120rpx;
		line-height: 120rpx;
		text-align: center;
		color: #4789E4;
		font-weight: 500;
		font-size: 34rpx;
		// background-image: url($imagesBasUrl+'/bg-rob.png');
		background-size: 100% 100%;
	}

	.fs {

		.yq-order,
		.order-status {
			color: #4CA0FF;
		}
	}

	.farmer {

		.yq-order,
		.order-status {
			color: #0BCA89;
		}
	}
</style>